package com.fearless.controller;

import com.fearless.crm.settings.entity.People;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class MyController {

    @RequestMapping(value = "/some")
    public ModelAndView doSome(String name,Integer age){
        System.out.println("处理器方法已执行");
        ModelAndView mv=new ModelAndView();
        mv.addObject("myName",name);
        mv.addObject("myAge",age);
        mv.setViewName("result");
        return mv;
    }

    @ResponseBody
    @RequestMapping(value = "/all")
    public People doAjax(String name, Integer age, Integer money){
        People people=new People(name,age,money);

        return people;
    }

 /*
*   处理器方法返回一个Student对象，我们将这个Student对象通过框架转为json，然后响应ajax请求
*
*   @ResponseBody: 作用：在处理器方法返回的java对象被转为json格式后，通过
*                        HTTPServletResponse将这个已经被转为json的java对象输出给浏览器
*
* */
    @ResponseBody
    @RequestMapping(value = "/play")
    public String doString(String name){
       System.out.println("doString处理器方法执行");

        return  name;
   }
}
